package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-26 00:35
 **/
public class LeetCode5948 {

    public boolean canBeValid(String s, String locked) {
        int left = 0, right = 0;
        for (int i = 0; i < s.length(); i++) {
            left += left == 0 || locked.charAt(i) == '1' && s.charAt(i) == '(' ? 1 : -1;
            if ((right += locked.charAt(i) == '1' && s.charAt(i) == ')' ? -1 : 1) < 0) {
                return false;
            }
        }
        return left == 0;
    }

}
